﻿<script type="text/javascript">
    var ecoburalId = "";
    var oldSelectecoburalId = "";
    var oldSelectecoburalName = "";
    $(function () {
        getButton("ecobural");
    });

    function ui_ecobural_init_list(toolbar) {
        $("#ui_ecobural_dg").datagrid({       //初始化datagrid
            url: "ashx/bg_ecobural.ashx?action=search",
            striped: true, rownumbers: true, pagination: true, pageSize: 20, singleSelect: true,
            idField: 'id',
            sortName: 'id',
            sortOrder: 'desc',
            pageList: [20, 40, 60, 80, 100],
            frozenColumns: [[
                { field: 'deadName', title: '死者姓名', sortable: true, width: 100 }
            ]],
            queryParams: {
                where: '1=1'
            },
            columns: [[
                       { field: 'deadAreaName', title: '所属地址', sortable: true, width: 120 },
                       { field: 'deadHomeAddr', title: '组别', width: 80 },
                       { field: 'relativeName', title: '联系人姓名', sortable: true, width: 120 },
                       { field: 'relativeTel', title: '联系电话', width: 120 },
                       { field: 'paradiseName', title: '所属骨灰堂', width: 120 },
                       { field: 'storetype', title: '生态葬方式', width: 120 },
                       { field: 'addtime', title: '时间', width: 120 }

            ]],
            toolbar: toolbar.length == 0 ? null : toolbar,   //请求回来的当前用户可以操作的按钮            
            onDblClickRow: function (rowIndex, rowData) {     //双击行弹框编辑
                ui_ecobural_store();
            }
        });

    }
    function ui_ecobural_dead_print(data, code) {
        if (!code || code.length==0) {
            $.show_warning("提示", "编号不存在，无法打印！");
            return;
        }
        ArgoxPrinter.A_EnumUSB();
        ArgoxPrinter.A_CreateUSBPort(1);
        var ret = ArgoxPrinter.A_getPrinterStatus();
        var msg = "";
        if (ret == 1) {
            msg = "打印机命令解析器忙碌中！";            
        }
        else if (ret == 2) {
            msg = "2 纸张用完或安装错误！";          //纸张用完或安装错误！            
        }
        else if (ret == 4) {
            msg = "4 碳带用完或安装错误！";                       //碳带用完或安装错误！";            
        }
        else if (ret == 8) {
            msg = "8 打印批次文档中！";           //打印批次文档中！";            
        }
        else if (ret == 16) {
            msg = "16 正在打印文件！";                 //正在打印文件！            
        }
        else if (ret == 32) {
            msg = "32 打印机暂停！";                 //打印机暂停！            
        }
        else if (ret == 64) {
            msg = "64 正在送出标签纸！";                 //正在送出标签纸！            
        }
        else if (ret == 9 || ret==0) {
            ArgoxPrinter.A_Set_Unit("n");	//n: 英吋, m:公厘
            ArgoxPrinter.A_Set_Syssetting(2, 0, 0, 0, 0);
            ArgoxPrinter.A_Set_Backfeed(320);		//回退值
            ArgoxPrinter.A_Set_Darkness(8);
            ArgoxPrinter.A_Set_Speed("E");
            //ArgoxPrinter.A_Draw_Box("A", 10, 10, 340, 120, 3, 3);
            //ArgoxPrinter.A_Draw_Line("A", 15, 40, 340, 3);
            ArgoxPrinter.A_Bar2d_QR(40, 20, 1, '4', 1, 'N', 1, data);
            //ArgoxPrinter.A_Bar2d_QR(140, 160, 1, '6', 10, 'N', 1, Data1);
            //ArgoxPrinter.A_Prn_Barcode(20, 30, 1, "E", 2, 6, 40, "B", 1, Data2);
            ArgoxPrinter.A_Prn_Text_TrueType(150, 20, 24, "宋体", 2, 600, 0, 0, 0, "CC", code, 1);
            //ArgoxPrinter.A_Get_Graphic_ColorBMP(10, 10, 1, "B", imgdir);
            ArgoxPrinter.A_Print_Out(1, 1, 1, 1);
            ArgoxPrinter.A_ClosePrn();
            return;
        }
        ArgoxPrinter.A_ClosePrn();
        $.show_warning("提示", msg);

    }
    //添加生态葬
    function ui_ecobural_add() {
        $('<div/>').dialog({
            id: 'ui_ecobural_add_dialog',
            href: 'html/ui_ecobural_edit.html',
            title: '生态葬',
            height: 400,
            width: 620,
            modal: true,
            buttons: [{
                id: "ui_ecobural_add_btn",
                text: '添 加',
                handler: function () {
                    $("#ui_ecobural_editform").form("submit", {
                        url: "ashx/bg_ecobural.ashx",
                        onSubmit: function (param) {
                            $('#ui_ecobural_add_btn').linkbutton('disable');    //点击就禁用按钮，防止连击
                            param.action = 'add';
                            if ($(this).form('validate'))
                                return true;
                            else {
                                $('#ui_ecobural_add_btn').linkbutton('enable');   //恢复按钮
                                return false;
                            }
                        },
                        success: function (data) {
                            var dataJson = eval('(' + data + ')');    //转成json格式
                            if (dataJson.success) {
                                $("#ui_ecobural_add_dialog").dialog('destroy'); //销毁dialog对象
                                $("#ui_ecobural_dg").datagrid("reload");
                                $.show_warning("提示", dataJson.msg);                                
                            } else {
                                $('#ui_ecobural_add_btn').linkbutton('enable');   //恢复按钮
                                $.show_warning("提示", dataJson.msg);
                            }
                        }
                    });
                }
            }],
            onLoad: function () {
                $("#ui_ecobural_dead_name").focus();
            },
            onClose: function () {
                $("#ui_ecobural_add_dialog").dialog('destroy');  //销毁dialog对象
            }
        });
    }
    function ui_ecobural_edit() {
        var rows = $("#ui_ecobural_dg").datagrid("getChecked");
        if (rows.length < 1) {
            $.show_warning("提示", "请先勾选要修改的行");
            return;
        }
        if (rows.length > 1) {
            $.show_warning("提示", "不支持批量修改");
            $("#ui_ecobural_dg").datagrid('clearSelections').datagrid('clearChecked');
            return;
        }
        var row = rows[0];
        $('<div/>').dialog({
            id: 'ui_ecobural_edit_dialog',
            href: 'html/ui_ecobural_edit.html',
            title: '修改生态葬',
            height: 400,
            width: 620,
            modal: true,
            buttons: [{
                id: "ui_ecobural_edit_btn",
                text: '修 改',
                handler: function () {
                    $("#ui_ecobural_editform").form("submit", {
                        url: "ashx/bg_ecobural.ashx",
                        onSubmit: function (param) {
                            $('#ui_ecobural_edit_btn').linkbutton('disable');    //点击就禁用按钮，防止连击
                            param.action = 'edit';
                            if ($(this).form('validate'))
                                return true;
                            else {
                                $('#ui_ecobural_edit_btn').linkbutton('enable');   //恢复按钮
                                return false;
                            }
                        },
                        success: function (data) {
                            var dataJson = eval('(' + data + ')');    //转成json格式
                            if (dataJson.success) {
                                $("#ui_ecobural_edit_dialog").dialog('destroy'); //销毁dialog对象
                                $("#ui_ecobural_dg").datagrid("reload");
                                $.show_warning("提示", dataJson.msg);
                                                          

                            } else {
                                $('#ui_ecobural_edit_btn').linkbutton('enable');   //恢复按钮
                                $.show_warning("提示", dataJson.msg);
                            }
                        }
                    });
                }
            }],
            onLoad: function () {
                $('#ui_ecobural_id').val(row.id);
                $('#ui_ecobural_dead_id').val(row.deadId);
                $('#ui_ecobural_relative_id').val(row.relativeId);
                
                $('#ui_ecobural_editform_paradise_code').combotree('setValue', row.paradisecode);

                $('#ui_ecobural_storetype').combobox('setValue', row.storetype);
                $('#ui_ecobural_dead_name').textbox('setValue', row.deadName);
                $('#ui_ecobural_dead_cardno').textbox('setValue', row.deadCardno);
                $('#ui_ecobural_dead_gender').combobox('setValue', row.deadGender);
                if (!row.deadNation || row.deadNation.length == 0) {
                    $('#ui_ecobural_dead_nation').textbox('setValue', "汉族");
                } else {
                    $('#ui_ecobural_dead_nation').textbox('setValue', row.deadNation);
                }
                $('#ui_ecobural_dead_addr').textbox('setValue', row.deadHomeAddr);
                $('#ui_ecobural_dead_areaId').combotree('setValue', row.deadAreaCode);
                $('#ui_ecobural_dead_firetime').datetimebox('setValue', row.deadFireTime);
                $('#ui_ecobural_relative_relation').textbox('setValue', row.relation);

                $('#ui_ecobural_relative_name').textbox('setValue', row.relativeName);
                $('#ui_ecobural_relative_tel').textbox('setValue', row.relativeTel);
                $('#ui_ecobural_relative_cardno').textbox('setValue', row.reltiveCardNo);
                $('#ui_ecobural_relative_areaId').combotree('setValue', row.reltiveAreaCode);
            },
            onClose: function () {
                $("#ui_ecobural_edit_dialog").dialog('destroy');  //销毁dialog对象
            }
        });

    }
    function ui_ecobural_delete() {
        var rows = $("#ui_ecobural_dg").datagrid("getChecked");
        if (rows.length < 1) {
            $.show_warning("提示", "请先勾选要删除的行");
            return;
        }
        $.messager.confirm('提示', '确定删除勾选的' + rows.length + '行？', function (r) {
            if (r) {
                para = {};
                para.action = "delete";
                para.timespan = new Date().getTime();
                para.id = "";
                var ids = [];
                $.each(rows, function (i, row) {
                    ids.push(row.id);
                });
                para.id = ids.join(",");
                $.ajax({
                    url: "ashx/bg_ecobural.ashx",
                    data: para,
                    type: "POST",
                    dataType: "json",
                    success: function (data) {
                        if (data.success) {
                            $.show_warning("提示", data.msg);
                            $("#ui_ecobural_dg").datagrid("reload").datagrid('clearSelections').datagrid('clearChecked');
                        } else {
                            $.show_warning("提示", data.msg);
                        }
                    }
                });
            }
        });
    }
    
    function ui_ecobural_searchdata() {
        var paradiseCode = $('#ui_ecobural_paradise_code').combotree('getValue');
        var storetype = $('#ui_ecobural_search_storetype').combobox('getValue');
        var areacode = $('#ui_ecobural_search_dead_areaId').combotree('getValue');
        var dname = $('#ui_ecobural_search_dname').textbox('getValue');
        var rname = $('#ui_ecobural_search_rname').textbox('getValue');
        var whereStr = "1=1";
        if (paradiseCode) {
            whereStr += " and paradisecode='"+paradiseCode+"'";
        } 
        if (storetype) {
            whereStr += " and storetype='" + storetype + "'";
        }
        if (areacode) {
            whereStr += " and areacode='" + areacode + "'";
        }
        if (dname) {
            whereStr += " and deadid in (select id from tbDead where name like '%"+dname+"%')";
        } 
        if (rname) {
            whereStr += " and deadid in (select id from tbDead where relativeid in (select id from tbRelative where  name like '%"+rname+"%'))"
        }
        $('#ui_ecobural_dg').datagrid("load", { where: whereStr });
    }

    function ui_ecobural_cleardata() {
        $('#ui_ecobural_search input').val('');
        $('#ui_ecobural_search select').val('select');
        $("#ui_ecobural_dg").datagrid('load', {});

        $("#ui_ecobural_dg").datagrid('clearSelections').datagrid('clearChecked');
        //$('#ui_ecobural_search').layout('collapse', 'east');    //隐藏
    }

    function to2digit(v) {
        return (Array(2).join(0) + v).slice(-2);
    }
    function to3digit(v) {
        return (Array(3).join(0) + v).slice(-3);
    }
</script>

<div id="ui_ecobural_layout" class="easyui-layout" data-options="fit:true,border:false">
    <div data-options="region:'east',split:true,border:true,collapsed:true" title="死者信息"
        style="width: 300px;">
        <table id="ui_ecobural_dead_dg" data-options="fit:true,border:false">
        </table>
    </div>
    <div data-options="region:'center',border:false">
        <table id="ui_ecobural_dg" data-options="fit:true,border:false">
        </table>
    </div>

    <div data-options="region:'west',split:true,border:true,collapsed:true" title="多条件查询"
        style="width: 280px;">
        <div id="ui_ecobural_search">
            <table class="tableForm" style="width: 100%; height: 100%; background: #F5F5F5;">
                <tr>
                    <th>骨灰堂：</th>
                    <td>
                        <input class="easyui-combotree" id="ui_ecobural_paradise_code" name="ui_ecobural_search_paradise_code"
                            data-options="url: 'ashx/bg_paradise.ashx?action=getall', lines:true" />
                    </td>
                </tr>
                <tr>
                    <th>生态葬方式：</th>
                    <td>
                        <select class="easyui-combobox" name="ui_ecobural_search_storetype" id="ui_ecobural_search_storetype" data-options="panelHeight:100,editable:false">
                            <option value="海葬">海葬</option>
                            <option value="树葬">树葬</option>
                            <option value="可降碱">可降碱</option>
                            <option value="深埋">深埋</option>
                        </select>
                    </td>
                </tr>
                <tr>
                    <th>死者地区：</th>
                    <td>
                        <input class="easyui-combotree" id="ui_ecobural_search_dead_areaId" name="ui_ecobural_dead_areaId"
                            data-options="url:'ashx/bg_area.ashx?action=getall', lines:true" />         
                    </td>
                </tr>
                <tr>
                    <th>死者姓名：</th>
                    <td>
                        <input type="text" class="easyui-textbox" id="ui_ecobural_search_dname" name="ui_ecobural_search_dname" data-options="min:0,max:9,precision:0">
                    </td>
                </tr>
                <tr>
                    <th>联系人姓名：
                    </th>
                    <td>
                        <input type="text" class="easyui-textbox" name="ui_ecobural_search_rname" id="ui_ecobural_search_rname" data-options="min:0,max:9,precision:0" />
                    </td>
                </tr>
                
                <tr>
                    <td>
                        <a href="javascript:void(0);" class="easyui-linkbutton" iconcls="icon-search" plain="true"
                            onclick="ui_ecobural_searchdata();">搜索</a>
                    </td>
                    <td>
                        <a href="javascript:void(0);" class="easyui-linkbutton" iconcls="icon-clear" plain="true"
                            onclick="ui_ecobural_cleardata();">清空条件</a>
                    </td>
                </tr>

            </table>
        </div>
    </div>
</div>
